#include <iostream>
#include <algorithm>

using namespace std;

int results[5][5] = 
{
    { 0, 2, 1, 1, 2 },
    { 1, 0, 2, 1, 2 },
    { 2, 1, 0, 2, 1 },
    { 2, 2, 1, 0, 1 },
    { 1, 1, 2, 2, 0 }
};

int main(int argc, char const *argv[])
{
    int n, a, b, *aarr, *barr, as, bs;
    int i, j;
    cin >> n >> a >> b;
    aarr = new int[a];
    barr = new int[b];
    for (i = 0; i < a; i++)
    {
        cin >> aarr[i]; 
    }
    for (i = 0; i < b; i++)
    {
        cin >> barr[i];
    }
    as = 0;
    bs = 0;
    for (i = 0; i < n; i++)
    {
        if (results[aarr[i % a]][barr[i % b]] == 1)
        {
            as++;
        }
        else if (results[aarr[i % a]][barr[i % b]] == 2)
        {
            bs++;
        }
    }
    cout << as << " " << bs;
    return 0;
}
